#include "core/time.hpp"

static f32 platform_get_time();

#if _WIN32
#include <Windows.h>

f32 platform_get_time()
{
    static LARGE_INTEGER s_second_tick{};
    if (s_second_tick.QuadPart == 0) {
        QueryPerformanceFrequency(&s_second_tick);
    }
    LARGE_INTEGER current{};
    QueryPerformanceCounter(&current);
    f32 seconds = (f32)current.QuadPart / (f32)s_second_tick.QuadPart;
    return seconds;
}
#else
    #include <sys/time.h>
f32 platform_get_time()
{
    timespec ts{};
    clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
    return (f32)ts.tv_sec + (f32)ts.tv_nsec * 1e-9f;
}
#endif

namespace core::util {
    f32 get_time() { return platform_get_time(); }
} // namespace core::util
